﻿using System.Windows;
using System.Windows.Controls;
using Aeon.Configuration;
using Aeon.Presentation.Browsers;

namespace Aeon.Emulator.Launcher.Views
{
    /// <summary>
    /// Provides the UI for mapped folder configuration.
    /// </summary>
    [DriveConfigurationView(typeof(MappedFolderConfiguration))]
    public partial class MappedFolderView : UserControl, IDriveConfigurationView
    {
        /// <summary>
        /// DriveConfiguration dependency property.
        /// </summary>
        public static readonly DependencyProperty DriveConfigurationProperty = DependencyProperty.Register("DriveConfiguration", typeof(MappedFolderConfiguration), typeof(MappedFolderView), new PropertyMetadata(null));

        /// <summary>
        /// Initializes a new instance of the MappedFolderView class.
        /// </summary>
        public MappedFolderView()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Gets or sets the drive configuration being viewed. This is a dependency property.
        /// </summary>
        public MappedFolderConfiguration DriveConfiguration
        {
            get { return (MappedFolderConfiguration)GetValue(DriveConfigurationProperty); }
            set { SetValue(DriveConfigurationProperty, value); }
        }

        /// <summary>
        /// Gets or sets the drive configuration being viewed.
        /// </summary>
        IDriveConfiguration IDriveConfigurationView.DriveConfiguration
        {
            get { return this.DriveConfiguration; }
            set { this.DriveConfiguration = (MappedFolderConfiguration)value; }
        }

        /// <summary>
        /// Invoked when the Browse button is clicked.
        /// </summary>
        /// <param name="sender">Source of the event.</param>
        /// <param name="e">Information about the event.</param>
        private void BrowseButton_Click(object sender, RoutedEventArgs e)
        {
            var browser = new FolderBrowserDialog()
            {
                Title = "Select folder...",
                ShowNewFolderButton = false
            };

            if(browser.ShowDialog(Window.GetWindow(this)))
                this.DriveConfiguration.HostPath = browser.Path;
        }
    }
}
